package com.java.str;
/**
 * 一个字母在单词中出现几次
 */

public class CharCounter {
	
	public static void main(String args[]) {
		System.out.println(new CharCounter().counter("LOVELOVEYOU", 'O'));
	}
	
	public static int counter(String s, char c) {
		int count = 0;
		for (int i = 0; i < s.length(); i++) {
			if (s.charAt(i) == c) {
				count++;
			}
		}
		return count;
	}

}